Skip to content

ref: eslint-plugin-boundaries #92031

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

TkDodo
Copy link
Contributor

@TkDodo TkDodo commented May 21, 2025

This PR adds the eslint-plugin-boundaries to define boundaries between our apps. In general, there are currently 3 boundaries we want to have:

  • sentry: the sentry app, including sentry related code in /tests.
  • gsAdmin: the getsentry app, including getsentry related code in /tests.
  • gsApp: the admin app

generally, the rules are:

  • sentry cannot import from gsAdmin or gsApp
  • gsApp can import sentry, but not gsAdmin
  • gsAdmin can import everything

Further, we want to extract sentry/app/components/core to their own “boundary”, which means that ideally:

  • everyone can import core/components
  • core/components can’t import anything from sentry, gsAdmin or gsApp.

As a first proof of concept, we’ve added specific rules for core/components/button to see what it takes to decouple it from the rest.

There are currently 23 violations that would need to be resolved, which is why the rule is set to warning only.

Once we are done with everything, this rule can and likely should replace the boundaries we have set via no-restricted-imports, as the rule is better grouped and more powerful.

@github-actions github-actions bot added the Scope: Frontend Automatically applied to PRs that change frontend components label May 21, 2025
Comment on lines +1079 to +1080
from: ['sentry*'],
allow: ['core*', 'sentry*'],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from and allow are micromatch patterns matched against the type defined in the above settings. I’ve “grouped” all sentry app related things as ”sentry-“ so that we can target them with ”sentry*” here.

So this means: sentry can import from sentry (itself) and from everything core, and since the default is disallow, everything else is forbidden and will yield a warning.

Comment on lines +996 to +1002
type: 'core-button',
pattern: 'static/app/components/core/button',
},
{
type: 'core',
pattern: 'static/app/components/core',
},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: we can remove core-button once we’ve isolated everything in core. core-button is a separate group now so that we get fewer violations. Since we match with core*, both groups are included.

@TkDodo TkDodo changed the title Tkdodo/ref/eslint plugin boundaries ref: eslint-plugin-boundaries May 21, 2025
@TkDodo TkDodo requested a review from a team May 21, 2025 15:26
Copy link
Member

@natemoo-re natemoo-re left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking great! The only feedback I have is that we might want core to allow imports from sentry/stories and sentry-test for the time being?

@JonasBa
Copy link
Member

JonasBa commented May 21, 2025

Looking great! The only feedback I have is that we might want core to allow imports from sentry/stories and sentry-test for the time being?

I think we need to scope that to only stories.tsx and .mdx files so that we don't end up with some component actually importing something from storybook 😅

@TkDodo
Copy link
Contributor Author

TkDodo commented May 23, 2025

Looking great! The only feedback I have is that we might want core to allow imports from sentry/stories and sentry-test for the time being?

I think we need to scope that to only stories.tsx and .mdx files so that we don't end up with some component actually importing something from storybook 😅

yes, good points. I made stories their own “boundary” so if you import from a story file in a production file, you’ll get the lint violation:

Screenshot 2025-05-23 at 10 51 25

I’ll do the same thing for tests, just in case!

Copy link

codecov bot commented May 23, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #92031      +/-   ##
==========================================
- Coverage   87.93%   87.62%   -0.31%     
==========================================
  Files       10174    10365     +191     
  Lines      583373   587523    +4150     
  Branches    22596    22594       -2     
==========================================
+ Hits       512966   514838    +1872     
- Misses      69955    72264    +2309     
+ Partials      452      421      -31     

@TkDodo
Copy link
Contributor Author

TkDodo commented May 23, 2025

test boundaries were a bit harder to set-up, as our tests are all over the place, as are mocks, fixtures and test-utils. I really think we should consolidate this in a follow-up, my idea would be to have all tests and test utils co-located in sub-directories called __tests__:

- my-component
  - __tests__
    - foo.spec.tsx
    - someTestHelper.ts
  - foo.tsx

anyways, with the current setup, we get the following remaining warnings, which I would try to tackle in a follow-up:

getsentry/sentry/static/app/components/core/button/buttonBar.tsx
  5:30  warning  core-button is not allowed to import sentry  boundaries/element-types
  6:21  warning  core-button is not allowed to import sentry  boundaries/element-types

getsentry/sentry/static/app/components/core/button/index.tsx
  5:35  warning  core-button is not allowed to import sentry  boundaries/element-types
  6:36  warning  core-button is not allowed to import sentry  boundaries/element-types
  7:21  warning  core-button is not allowed to import sentry  boundaries/element-types

getsentry/sentry/static/app/components/core/button/linkButton.tsx
  5:35  warning  core-button is not allowed to import sentry  boundaries/element-types
  6:18  warning  core-button is not allowed to import sentry  boundaries/element-types
  7:36  warning  core-button is not allowed to import sentry  boundaries/element-types
  8:21  warning  core-button is not allowed to import sentry  boundaries/element-types

getsentry/sentry/static/app/components/core/button/styles.chonk.tsx
  4:36  warning  core-button is not allowed to import sentry  boundaries/element-types
  5:27  warning  core-button is not allowed to import sentry  boundaries/element-types

getsentry/sentry/static/app/components/core/button/styles.tsx
  4:33  warning  core-button is not allowed to import sentry  boundaries/element-types
  5:21  warning  core-button is not allowed to import sentry  boundaries/element-types

getsentry/sentry/static/app/components/core/button/useButtonFunctionality.tsx
  1:23  warning  core-button is not allowed to import sentry  boundaries/element-types

✖ 14 problems (0 errors, 14 warnings)

@TkDodo TkDodo marked this pull request as ready for review May 23, 2025 11:31
@TkDodo TkDodo requested review from a team as code owners May 23, 2025 11:31
@TkDodo TkDodo requested review from natemoo-re and JonasBa May 23, 2025 11:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scope: Frontend Automatically applied to PRs that change frontend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants